package demo.sort;

/**
 * @Author: admin
 * @Description:
 * @Date: Create in 2021/6/6-15:48
 */
public class ShellSort {

    public static void main(String[] args) {

    }

    static void swap(int[] arr,int i,int pos){
        int temp = arr[i];
        arr[i]=arr[pos];
        arr[pos]=temp;
    }

    public static   int[] sort(int[] arr){

        int h=1;
        while (h<=arr.length/3){
            h = h * 3 +1;
        }


       for(int gap=h;gap>0;gap=(gap-1)/3){
           for (int i = gap; i < arr.length; i++) {
               for (int j = i; j > gap-1  ; j-=gap) {
                   if(arr[j]<arr[j-gap]){
                       swap(arr,j,j-gap);
                   }else {
                       break;
                   }
               }
//            System.out.println(maxPos);

               //判断是否转移的时候，最小值的位置是

           }
       }


        return  arr;
    };

}
